<?php

namespace App\Models;

// use Illuminate\Database\Eloquent\Model;
use App\Models\BaseModel as Model;

class Delivery extends Model
{
    protected $primaryKey = 'delivery_id';

    protected $casts = [
        'created_at' => 'Y-m-d H:i:s',
        'updated_at' => 'Y-m-d H:i:s',
    ];

    protected $fillable = ['order_bn', 'member_id', 'type', 'status', 'ship_company', 'ship_number', 'remark', 'created_at', 'updated_at'];

    /**
     * 会员信息
     * @return \Illuminate\Database\Eloquent\Relations\belongsTo
     */
    public function member()
    {
        return $this->belongsTo(Member::class, 'member_id');
    }

    /**
     * 物流公司
     * @return \Illuminate\Database\Eloquent\Relations\belongsTo
     */
    public function expresscompany()
    {
        return $this->belongsTo(ExpressCompany::class, 'ship_company');
    }

    /**
     * 发货单详情
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function detail()
    {
        return $this->hasMany(DeliveryDetail::class, 'delivery_id')->with(['goods']);
    }
}
